package com.demo.controller;


import com.demo.domain.CtCommodity;
import com.demo.service.impl.CtCommodityServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CtCommodity)表控制层
 *
 * @author makejava
 * @since 2021-07-07 09:09:08
 */
@RestController
public class CtCommodityController {
    /**
     * 服务对象
     */
    @Resource
    private CtCommodityServiceImpl ctCommodityService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne2")
    public CtCommodity selectOne(Integer id) {
        return this.ctCommodityService.queryById(id);
    }
    @GetMapping("selectAll2")
    public List<CtCommodity> selectAll(){
        return this.ctCommodityService.queryAllByLimit();
    }
    @GetMapping("insertById2")
    public CtCommodity insertById(CtCommodity ctCommodity){
        return this.ctCommodityService.insert(ctCommodity);
    }
    @PostMapping("updateById2")
    public CtCommodity updateById(CtCommodity ctCommodity){
        return this.ctCommodityService.update(ctCommodity);
    }
    @PostMapping("deleteById2/{id}")
    public boolean deleteById(@PathVariable int id){
        return this.ctCommodityService.deleteById(id);
    }
    @GetMapping("insertInfo")
    public CtCommodity insertInfo(String title,String price,String label_ids,String banner_images,String content,String person_name,String person_mobile,Integer is_face){
        CtCommodity commodity = new CtCommodity();
        commodity.setCTitle(title);
        if(is_face==1){
            commodity.setCSale("0");
        }else{
            commodity.setCSale(price);
        }

        commodity.setCImg(banner_images);
        commodity.setCType(label_ids);
        commodity.setCContent(content);
        commodity.setCPerson(person_name);
        commodity.setCPhone(person_mobile);
        return this.ctCommodityService.insert(commodity);
    }
}